//
//  MovieTheatreVC.m
//  Movie
//
//  Created by huazi on 15/11/2.
//  Copyright © 2015年 huazi. All rights reserved.
//

#import "MovieTheatreVC.h"
#import "BaseEntity.h"

#import "HotMovieView.h"
#import "SurroundingView.h"

@interface MovieTheatreVC ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView          *scrollView;
@property (nonatomic, strong) UISegmentedControl    * segment;

@end

@implementation MovieTheatreVC


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setSubviews];
}


- (void)setSubviews
{
    [self initNav];
    [self initScrollView];
}

- (void)initScrollView
{
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, DeviceWidth,DeviceHeight - 49 - 64)];
    self.scrollView.delegate = self;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.directionalLockEnabled = YES;
    self.scrollView.contentSize = CGSizeMake(DeviceWidth *2, self.scrollView.height);
    [self.view addSubview:self.scrollView];
    
    [self setScrollViewSubView];
}

- (void)setScrollViewSubView
{
    HotMovieView * hotView = [[HotMovieView alloc]initWithFrame:self.scrollView.bounds];
    
    [self.scrollView addSubview:hotView];
    
    SurroundingView * surroundView = [[SurroundingView alloc]initWithFrame:CGRectMake(DeviceWidth, 0, DeviceWidth, self.scrollView.height)];
    
    [self.scrollView addSubview:surroundView];
    
    
}

- (void)initNav
{
    [self setNavTitleView];
    [self setNavItems];
}

- (void)setNavItems
{
    //@"arroe_down.png" 暂时先不放
    
    [self setNavLeftItemWith:@"安徽" andImage:nil];
    [self setNavRightItemWith:@"" andImage:[UIImage imageNamed:@"search_icon.png"]];
    
}

- (void)setNavTitleView
{
    self.segment = [[UISegmentedControl alloc]initWithItems:@[@"热映",@"周边"]];
    
    self.segment.frame =CGRectMake(0, 0, 100, 30);
    [self.segment setCornerRadius:10.0];
    self.segment.selectedSegmentIndex = 0;
    [self.segment setBackgroundImage:[UIImageView imageWithColor:UIColorFromRGB(166, 56, 51)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [self.segment setBackgroundImage:[UIImageView imageWithColor:[UIColor whiteColor]] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
    [self.segment setTintColor:[UIColor whiteColor]];
    [self.segment setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];
    [self.segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    
    self.navigationItem.titleView = self.segment;
}

#pragma mark - scrollViewDelegate

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    self.segment.selectedSegmentIndex = scrollView.contentOffset.x /DeviceWidth;
}

#pragma  mark - ButtonAction

- (void)segmentAction:(UISegmentedControl *)segment
{
    [self.scrollView setContentOffset:CGPointMake(DeviceWidth * segment.selectedSegmentIndex, 0) animated:YES];
}

- (void)rightItemClick:(id)sender
{
    NSLog(@"暂时不做");
}

- (void)leftItemClick:(id)sender
{
    NSLog(@"城市搜索");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
